package com.zxf.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.zxf.dao.ArticleMapper;
import com.zxf.dao.ContentMapper;
import com.zxf.pojo.Article;
import com.zxf.pojo.Content;
import com.zxf.pojo.Params;


@Service  
//默认将类中的所有函数纳入事务管理.  
@Transactional  
public class ArticleService {
	
	 
	    @Autowired  
	    private ArticleMapper articleMapper;
	    
	    @Autowired  
	    private ContentMapper contentMapper;


		public List getArticleList() {
			// TODO Auto-generated method stub
			return articleMapper.getArticleallList();
		}
		// 保存文章信息
		public int savearticle(Article article) {
			
			return articleMapper.insert(article);
			
			
		}
		// 保存文章内容
		public int savecontent(Content content) {
			
			return contentMapper.insert(content);
			
		}
		public List getArticleList(int pagenum, int numbers) {
			// TODO Auto-generated method stub
			List userMap = new ArrayList();
			HashMap paramsmap =  new HashMap();
			paramsmap.put("typeID", pagenum);
			paramsmap.put("limit", numbers);
			userMap = articleMapper.getArticleListindex(paramsmap);
			return userMap;
		}
		public int getartcletotle(Params params, Article article) {
			HashMap paramsmap =  new HashMap();
			paramsmap.put("start", params.getStart());
			paramsmap.put("limit", params.getLimit());
			paramsmap.put("articleID", article.getArticleID());
			paramsmap.put("typeid", article.getTypeid());
			paramsmap.put("channelid", article.getChannelid());
			paramsmap.put("title", article.getTitle());
			paramsmap.put("author", article.getAuthor());
			paramsmap.put("source", article.getSource());
			paramsmap.put("startdate", params.getStartdate());
			paramsmap.put("enddate", params.getEnddate());
			List userMap = new ArrayList();
			return articleMapper.getartcletotle(paramsmap);
		}
		//带搜索参数的
		public List getArticleList(Params params, Article article) {
			// TODO Auto-generated method stub
			HashMap paramsmap =  new HashMap();
			paramsmap.put("start", params.getStart());
			paramsmap.put("limit", params.getLimit());
			paramsmap.put("articleID", article.getArticleID());
			paramsmap.put("typeid", article.getTypeid());
			paramsmap.put("channelid", article.getChannelid());
			paramsmap.put("title", article.getTitle());
			paramsmap.put("author", article.getAuthor());
			paramsmap.put("source", article.getSource());
			paramsmap.put("startdate", params.getStartdate());
			paramsmap.put("enddate", params.getEnddate());
			List userMap = new ArrayList();
			return articleMapper.getArticleList(paramsmap);
		}
		//删除文章
		public int delarticle(int i) {
			// TODO Auto-generated method stub
			return articleMapper.deleteByPrimaryKey(i);
		}
		public int delcontent(String title) {
			// TODO Auto-generated method stub
			return contentMapper.delcontent(title);
		}
		//查看详细信息
		public Article detailarticle(int parseInt) {
			// TODO Auto-generated method stub
			return articleMapper.selectByPrimaryKey(parseInt);
		}
		//查看详细信息
		public Content detailcontent(String title) {
			// TODO Auto-generated method stub
			return contentMapper.detailcontent(title);
		}
		public int uparticle(Article article) {
			// 修改信息
			return articleMapper.uparticle(article);
		}
		public int upcontent(Content content) {
			// 修改信息
			return contentMapper.upcontent(content);
		}
		//分类
		public List getArticleList(int i) {
			// TODO Auto-generated method stub
			return null;
		}
		//上一篇
		public Article findPrevious(int artid, int typeid) {
			// TODO Auto-generated method stub
			HashMap paramsmap =  new HashMap();
			paramsmap.put("artid", artid);
			paramsmap.put("typeid", typeid);
			return articleMapper.findPrevious(paramsmap);
		}
		//下一篇
		public Article findNextarticle(int artid, int typeid) {
			// TODO Auto-generated method stub
			HashMap paramsmap =  new HashMap();
			paramsmap.put("artid", artid);
			paramsmap.put("typeid", typeid);
			return articleMapper.findNextarticle(paramsmap);
		}  
	  
	
}
